// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
/** 获取所有书籍信息 GET /books */
export async function getAllBooks(options?: { [key: string]: any }) {
  return request<API.BookInfo>('/books', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 搜索书籍信息 GET /books/{name} */
export async function searchBook(name:string,options?: { [key: string]: any }) {
  const url = '/books/find/' + name;
  return request<API.BookInfo>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取单个书籍信息 GET /books/{id} */
export async function getBookById(id: string ,options?: { [key: string]: any }) {
  const url = '/books/' + id;
  return request<API.BookDetail>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 添加书籍信息 POST /books */
export async function addBookInfo(body: API.AddBookParams, options?: { [key: string]: any }) {
  return request<API.BookDetail>('/books/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 获取单个书籍信息 GET /books/{id} */
export async function getBookCommendById(id: number ,options?: { [key: string]: any }) {
  const url = '/comments/' + id;
  return request<API.BookComment>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 添加单个书籍评论 POST /comments/ */
export async function addBookComment(body: API.CommentParams, options?: { [key: string]: any }) {
  return request<API.CommentContent>('/comments/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}



/** 借阅 POST /borrows/ */
export async function borrowBook(body: API.BorrowParams, id: number, options?: { [key: string]: any }) {
  const url = '/borrows/' + id;
  return request<API.BorrowResult>(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 获取个人借阅历史信息 GET /borrows/{userid} */
export async function getBorrowHistoryById(userid: number ,options?: { [key: string]: any }) {
  const url = '/borrows/' + userid;
  return request<API.BorrowListResult>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取推荐书籍信息 GET /books/{userid} */
export async function Recommend(userid: number ,options?: { [key: string]: any }) {
  const url = '/users/recommend/' + userid;
  return request<API.BookDetail>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取推荐书籍信息 GET /information/{userid} */
export async function getInformationById(userid: number ,options?: { [key: string]: any }) {
  const url = '/information/' + userid;
  return request<API.Information>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取当前的用户 GET /api/currentUser */
export async function getCurrentUserById(userid: string, options?: { [key: string]: any }) {
  const url = '/users/' + userid;
  return request<API.CurrentUser>(url, {
    method: 'GET',
    ...(options || {}),
  });
}

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/login/outLogin', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /tokens */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.CurrentUser>('/users/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}





/*得到个人图书馆信息 GET*/
export async function getLibraryById(userid: number | undefined, options?: { [p: string]: any }) {
  const url = '/libraries/' + userid;
  return request<API.IndividualLibBooks>(url, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    method: 'GET',
    ...(options || {}),
  });
}
